#ifndef __ANIMATION_H__
#define __ANIMATION_H__
#include "Task.h"
class Animation;

class AnimationDelegate
{
public:
	AnimationDelegate();
	~AnimationDelegate();

protected:

	friend class Animation;

	virtual void animateStarted(Animation* animation) = 0;

	virtual void animateCompleted(Animation* animation) = 0;

	virtual void animateStep(Animation* animation) = 0;
	
	virtual void animateCanceled(Animation* animation) = 0;
};

class Animation
{
public:
	Animation(int max_step = 5, int grain = 50);
	virtual ~Animation();

	virtual bool step(int step_num) = 0;

	bool isAnimate()
	{
		return animating_;
	}


	int getMaxStepNum();

	void setDelegate(AnimationDelegate* delegate);
	AnimationDelegate* getDelegate();
protected:
	friend class AnimationTask;

	void startAnimation();

	bool run();
private:


	void postTask();

	int animate_step_;

	bool animating_;

	int max_step_num_;

	int grain_;

	AnimationDelegate* delegate_;
};

class AnimationTask : public Task
{
public:
	AnimationTask(Animation* animation);
	~AnimationTask();

	virtual bool run(void* param);

private:
	Animation* ani_;
};

#endif // __ANIMATION_H__